var verifyPostorder = function(postorder) {
  let pre = -1;
  // 后序遍历，最后一个为根节点
  function inorder(nums, l, r) {
    if(l > r) return true;
    let ind = l;
    
    while(nums[ind] < nums[r]) ++ind;
    if(!inorder(nums, l, ind - 1)) return false;
    // nums[r] 当前根节点
    if(pre != -1 && nums[r] <= nums[pre]) return false;
    pre = r;
    
    if (!inorder(nums, ind, r - 1)) return false;
    return true;
  }

  return inorder(postorder, 0, postorder.length - 1)
};